package com.jtbd.dto.http;

import com.jtbd.domain.UserStudent;
import com.jtbd.dto.db.UserStudentInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

@Data
@Schema(description = "用户学生信息")
public class UserStudentHttpDto {
    @Schema(description = "用户基础信息")
    @NotNull
    private UserInfoHttpDto userInfo;
    @Schema(description = "年级id")
    private Long gradeId;
    @Schema(description = "年级名称")
    private String gradeName;
    @Schema(description = "班级名称")
    private String className;
    @Schema(description = "学校名称")
    private String schoolName;
    @Schema(description = "学校id")
    private Long schoolId;


    public static UserStudentInfo getUserStudentInfo(UserStudentHttpDto httpDto) {
        UserStudent userStudent = new UserStudent();
        userStudent.setUid(httpDto.userInfo.getId());
        userStudent.setGradeId(httpDto.gradeId);
        userStudent.setGradeName(httpDto.gradeName);
        userStudent.setClassName(httpDto.className);
        userStudent.setSchoolId(httpDto.schoolId);
        userStudent.setClassName(httpDto.schoolName);
        return new UserStudentInfo(UserInfoHttpDto.getUserInfo(httpDto.userInfo), userStudent);
    }

    /**
     * 将UserStudentInfo对象转换为UserStudentHttpDto对象
     *
     * @param userStudentInfo 用户学生信息对象，包含用户基本信息和学生详细信息
     * @return UserStudentHttpDto 用户学生HTTP传输对象，用于网络传输
     */
    public static UserStudentHttpDto getUserStudentHttpDto(UserStudentInfo userStudentInfo) {
        UserStudentHttpDto userStudentHttpDto = new UserStudentHttpDto();
        // 转换用户基本信息
        userStudentHttpDto.setUserInfo(UserInfoHttpDto.getUserInfoHttpDto(userStudentInfo.getUserInfo()));
        // 设置学生相关信息
        userStudentHttpDto.setGradeId(userStudentInfo.getUserStudent().getGradeId());
        userStudentHttpDto.setGradeName(userStudentHttpDto.gradeName);
        userStudentHttpDto.setClassName(userStudentInfo.getUserStudent().getClassName());
        userStudentHttpDto.setSchoolName(userStudentInfo.getUserStudent().getSchoolName());
        userStudentHttpDto.setSchoolId(userStudentInfo.getUserStudent().getSchoolId());
        return userStudentHttpDto;
    }

}
